Skip to content

fix: return reverted field of logs set to true if tipset was reverted#7172

Merged
akaladarshi merged 6 commits into
mainfrom
akaladarshi/return-logs-reverted
Jun 25, 2026
Merged

fix: return reverted field of logs set to true if tipset was reverted#7172
akaladarshi merged 6 commits into
mainfrom
akaladarshi/return-logs-reverted

Conversation

@akaladarshi

@akaladarshi akaladarshi commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary of changes

Changes introduced in this pull request:

  • Read the head change (apply and reverted) and fetch the logs live for both
  • Refactor the existing logs matching

Reference issue to close (if applicable)

Closes #7096

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed eth_subscribe log delivery during reorgs so reorg-reverted logs are re-emitted with removed: true, before logs from the replacing chain head.
    • Improved installed log filters (eth_getFilterLogs / eth_getFilterChanges) to return only newly observed events by tracking per-filter event delivery positions.
  • Tests
    • Expanded end-to-end eth_subscribe coverage into a filter-matrix validating address/topic wildcard behavior (including trailing wildcards) and correct inclusion/exclusion across concurrent subscriptions.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds reorg-removed log emission for eth_subscribe("logs") by broadcasting head-change log batches, tracking reverted events explicitly, polling installed filters by seen event positions, and updating the stateful subscription test matrix.

Changes

eth_subscribe reorg-removed logs pipeline

Layer / File(s) Summary
Core contracts and state
src/rpc/methods/chain.rs, src/rpc/methods/eth/filter/mod.rs, src/rpc/methods/eth.rs, src/rpc/methods/eth/pubsub.rs, src/rpc/mod.rs
Adds EventRevertStatus, SeenEventPositions, PathChange::tipset(), LogsFeed, and the RPCState.eth_logs_feed field.
RPC state recompute policy
src/state_manager/state_computation.rs
Adds rpc_state_recompute_policy() and threads the resolved policy through executed-tipset loading.
Event revert-status wiring
src/rpc/methods/eth/filter/event.rs, src/rpc/methods/eth/filter/mod.rs
Changes EventFilter polling state to seen_positions, updates event collection to accept EventRevertStatus, sets CollectedEvent.reverted from that status, removes EthFilterSpec matcher logic and related tests, and adds a revert-status unit test.
Head-change log collection and filter polling
src/rpc/methods/eth.rs
Adds eth_logs_for_head_change, introduces poll_event_filter, and updates installed filter log queries to use seen-position deltas.
Shared logs feed subscription
src/rpc/methods/eth/pubsub.rs
Adds the shared broadcast logs feed, initializes it lazily, rewrites spawn_logs to consume shared batches, and expands log_matches tests.
RPCState feed initialization
src/daemon/mod.rs, src/rpc/methods/sync.rs, src/tool/offline_server/server.rs, src/tool/subcommands/api_cmd/generate_test_snapshot.rs, src/tool/subcommands/api_cmd/test_snapshot.rs
Initializes eth_logs_feed in every RPCState construction site used by daemon, offline server, sync tests, and snapshot helpers.
eth_subscribe logs filter matrix
src/tool/subcommands/api_cmd/stateful_tests.rs
Rewrites the stateful eth_subscribe_logs test into a multi-subscription filter matrix and renames the registered scenario.
Changelog entry
CHANGELOG.md
Adds the unreleased fixed-note for the eth_subscribe logs reorg behavior.

Sequence Diagram(s)

sequenceDiagram
  participant ChainHeadChanges
  participant run_logs_feed
  participant eth_logs_for_head_change
  participant collect_events_from_messages
  participant LogsFeed
  participant spawn_logs
  participant log_matches
  participant SubscriptionSink

  ChainHeadChanges->>run_logs_feed: head change event
  run_logs_feed->>eth_logs_for_head_change: PathChange<Tipset>
  eth_logs_for_head_change->>collect_events_from_messages: collect with revert status
  collect_events_from_messages-->>eth_logs_for_head_change: CollectedEvent list
  eth_logs_for_head_change-->>run_logs_feed: Vec<EthLog>
  run_logs_feed->>LogsFeed: broadcast batch
  LogsFeed-->>spawn_logs: shared batch
  spawn_logs->>log_matches: filter by EthFilterSpec
  log_matches-->>spawn_logs: matched logs
  spawn_logs->>SubscriptionSink: forward logs
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • ChainSafe/forest#5749: Introduced the earlier eth_subscribe logs pipeline that this PR replaces with shared-feed head-change delivery.
  • ChainSafe/forest#6941: Modifies the same src/rpc/methods/eth/pubsub.rs logs subscription path.
  • ChainSafe/forest#7116: Touches the same Ethereum event collection and state-loading areas used by this PR.

Suggested reviewers

  • hanabi1224
  • LesnyRumcajs
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The removed-log behavior is addressed, but the visible test changes don't show an end-to-end reorg case for emitted removed: true logs. Add an integration test that forces a reorg and asserts reverted logs are emitted with removed: true before the replacement tipset logs.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: emitting removed logs for reverted tipsets during reorgs.
Out of Scope Changes check ✅ Passed The other code changes appear to support the same logs-subscription fix and its test plumbing, with no clearly unrelated edits shown.
Docstring Coverage ✅ Passed Docstring coverage is 94.23% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch akaladarshi/return-logs-reverted
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch akaladarshi/return-logs-reverted

Comment @coderabbitai help to get the list of available commands.

@akaladarshi akaladarshi added the RPC requires calibnet RPC checks to run on CI label Jun 11, 2026
@akaladarshi akaladarshi force-pushed the akaladarshi/return-logs-reverted branch from acbad44 to 7141458 Compare June 18, 2026 12:00
@akaladarshi akaladarshi marked this pull request as ready for review June 18, 2026 12:00
@akaladarshi akaladarshi requested a review from a team as a code owner June 18, 2026 12:00
@akaladarshi akaladarshi requested review from LesnyRumcajs and hanabi1224 and removed request for a team June 18, 2026 12:00
@akaladarshi akaladarshi force-pushed the akaladarshi/return-logs-reverted branch 2 times, most recently from 1d0b496 to e1043a0 Compare June 18, 2026 12:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/rpc/methods/eth.rs`:
- Around line 3318-3320: The `eth_getFilterLogs` method is incorrectly using the
`poll_event_filter` helper which mutates internal state by updating
`seen_positions` at lines 3353-3361. This makes the method non-idempotent,
causing repeated calls to return different results and breaking subsequent
`eth_getFilterChanges` calls. Instead of calling `poll_event_filter`, directly
collect the filter's full result set from the canonical chain without updating
any poll state. Keep the `poll_event_filter` usage only in
`eth_getFilterChanges` where state mutation is appropriate. Extract the core
logic for collecting events from the filter without the state mutation part.

In `@src/state_manager/state_computation.rs`:
- Around line 70-84: The load_executed_tipset_with_receipt method is bypassing
the stale-cache validation and removal guard that is implemented in the
load_executed_tipset_with_cache method. This causes stale cached ExecutedTipset
entries to be returned after head reset or garbage collection events. Apply the
same cache validity checking and invalidation logic that exists in
load_executed_tipset_with_cache (Lines 99-107) to the
load_executed_tipset_with_receipt method before or after the get_or_insert_async
call to ensure stale entries are properly removed from the cache in the
receipt-specific flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9018da5a-761b-49ea-8e98-3507519807fa

📥 Commits

Reviewing files that changed from the base of the PR and between f574cdf and e1043a0.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • src/daemon/mod.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/filter/event.rs
  • src/rpc/methods/eth/filter/mod.rs
  • src/rpc/methods/eth/pubsub.rs
  • src/rpc/methods/sync.rs
  • src/rpc/mod.rs
  • src/state_manager/state_computation.rs
  • src/tool/offline_server/server.rs
  • src/tool/subcommands/api_cmd/generate_test_snapshot.rs
  • src/tool/subcommands/api_cmd/stateful_tests.rs
  • src/tool/subcommands/api_cmd/test_snapshot.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread src/rpc/methods/eth.rs
Comment thread src/state_manager/state_computation.rs
@akaladarshi akaladarshi marked this pull request as draft June 18, 2026 12:36
@akaladarshi akaladarshi force-pushed the akaladarshi/return-logs-reverted branch from a967d70 to 33c3fb8 Compare June 18, 2026 16:25
@akaladarshi akaladarshi marked this pull request as ready for review June 18, 2026 16:46
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.74194% with 120 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.07%. Comparing base (39232f4) to head (4aed040).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/eth.rs 0.00% 64 Missing ⚠️
src/rpc/methods/eth/pubsub.rs 81.77% 35 Missing ⚠️
src/state_manager/state_computation.rs 40.00% 15 Missing ⚠️
src/rpc/methods/chain.rs 0.00% 4 Missing ⚠️
src/daemon/mod.rs 0.00% 1 Missing ⚠️
...tool/subcommands/api_cmd/generate_test_snapshot.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/eth/filter/event.rs 84.48% <100.00%> (ø)
src/rpc/methods/eth/filter/mod.rs 88.43% <100.00%> (-0.97%) ⬇️
src/rpc/methods/sync.rs 73.52% <100.00%> (+0.15%) ⬆️
src/rpc/mod.rs 90.03% <ø> (ø)
src/tool/offline_server/server.rs 27.57% <100.00%> (+0.34%) ⬆️
src/tool/subcommands/api_cmd/test_snapshot.rs 82.20% <100.00%> (+0.10%) ⬆️
src/daemon/mod.rs 24.63% <0.00%> (-0.04%) ⬇️
...tool/subcommands/api_cmd/generate_test_snapshot.rs 6.97% <0.00%> (-0.04%) ⬇️
src/rpc/methods/chain.rs 59.01% <0.00%> (-0.24%) ⬇️
src/state_manager/state_computation.rs 76.27% <40.00%> (-0.89%) ⬇️
... and 2 more

... and 11 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f2a958e...4aed040. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/state_manager/state_computation.rs Outdated
@akaladarshi akaladarshi force-pushed the akaladarshi/return-logs-reverted branch from 33c3fb8 to 9a4b513 Compare June 19, 2026 09:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/state_manager/state_computation.rs (1)

63-77: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Align receipt-path cache reads with stale-cache invalidation logic

load_executed_tipset_with_receipt bypasses the stale-cache validation used by load_executed_tipset_with_cache, so it can return invalid cached entries after head reset/GC. Please apply the same pre-read validation/removal guard here before get_or_insert_async (Line 63-Line 77).

Suggested patch
 pub async fn load_executed_tipset_with_receipt(
     &self,
     msg_ts: &Tipset,
     receipt_ts: &Tipset,
 ) -> anyhow::Result<ExecutedTipset> {
+    // Keep cache-validity behavior consistent with load_executed_tipset_with_cache.
+    if msg_ts.epoch() >= self.heaviest_tipset().epoch()
+        && let Some(cached) = self.cache.get(msg_ts.key())
+    {
+        if StateTree::new_from_root(self.db(), &cached.state_root).is_ok() {
+            return Ok(cached);
+        } else {
+            self.cache.remove(msg_ts.key());
+        }
+    }
+
     self.cache
         .get_or_insert_async(msg_ts.key(), async move {
             self.load_executed_tipset_inner(
                 msg_ts,
                 Some(receipt_ts),
                 Self::rpc_state_recompute_policy(),
             )
             .await
         })
         .await
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/state_manager/state_computation.rs` around lines 63 - 77, The
load_executed_tipset_with_receipt method does not perform the same stale-cache
validation that load_executed_tipset_with_cache applies before reading from
cache, which allows invalid cached entries to persist after head reset or
garbage collection operations. Apply the same pre-read validation and removal
guard logic to load_executed_tipset_with_receipt before the get_or_insert_async
call to ensure stale cache entries are properly invalidated before retrieval.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/state_manager/state_computation.rs`:
- Around line 63-77: The load_executed_tipset_with_receipt method does not
perform the same stale-cache validation that load_executed_tipset_with_cache
applies before reading from cache, which allows invalid cached entries to
persist after head reset or garbage collection operations. Apply the same
pre-read validation and removal guard logic to load_executed_tipset_with_receipt
before the get_or_insert_async call to ensure stale cache entries are properly
invalidated before retrieval.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4aa9f30f-5851-46ce-8802-e0a7032902b1

📥 Commits

Reviewing files that changed from the base of the PR and between 33c3fb8 and 9a4b513.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • src/daemon/mod.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/filter/event.rs
  • src/rpc/methods/eth/filter/mod.rs
  • src/rpc/methods/eth/pubsub.rs
  • src/rpc/methods/sync.rs
  • src/rpc/mod.rs
  • src/state_manager/state_computation.rs
  • src/tool/offline_server/server.rs
  • src/tool/subcommands/api_cmd/generate_test_snapshot.rs
  • src/tool/subcommands/api_cmd/stateful_tests.rs
  • src/tool/subcommands/api_cmd/test_snapshot.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
✅ Files skipped from review due to trivial changes (4)
  • src/tool/offline_server/server.rs
  • src/tool/subcommands/api_cmd/generate_test_snapshot.rs
  • CHANGELOG.md
  • src/rpc/methods/sync.rs
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/tool/subcommands/api_cmd/test_snapshot.rs
  • src/daemon/mod.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/eth/filter/event.rs
  • src/rpc/mod.rs
  • src/rpc/methods/eth.rs
  • src/tool/subcommands/api_cmd/stateful_tests.rs
  • src/rpc/methods/eth/pubsub.rs
  • src/rpc/methods/eth/filter/mod.rs

Comment thread src/tool/subcommands/api_cmd/stateful_tests.rs
@akaladarshi akaladarshi marked this pull request as draft June 19, 2026 17:32
@akaladarshi akaladarshi force-pushed the akaladarshi/return-logs-reverted branch from 627bda7 to d788dc5 Compare June 24, 2026 19:27
@akaladarshi akaladarshi marked this pull request as ready for review June 24, 2026 20:00
@akaladarshi akaladarshi added this pull request to the merge queue Jun 25, 2026
Merged via the queue into main with commit 4369abd Jun 25, 2026
42 checks passed
@akaladarshi akaladarshi deleted the akaladarshi/return-logs-reverted branch June 25, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eth_subscribe logs: emit reorg-removed (removed: true) logs in subscription

2 participants